package com.zretc.kscxmz.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.kscxmz.entity.Position;
import com.zretc.kscxmz.services.PositionService;
import com.zretc.kscxmz.services.impl.PositionServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/Position")
public class PositionController {
    private static final Logger logger = LoggerFactory.getLogger(PositionController.class);

    @Autowired
    private PositionService positionService;

    @RequestMapping("/getPositionByPage")
    public @ResponseBody
    PageInfo<Position> getPositionByPage(@RequestParam(value = "pageNum")String pageNum,
                                         @RequestParam(value = "pageSize")String pageSize
    ){
        logger.info("======查询职位列表======");
        logger.info("====pageNum:"    + pageNum);
        logger.info("====pagleSize:"   + pageSize);

        Map<String, String> map = new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        //调用业务层
        PageInfo<Position> positionByPage = positionService.getPositionByPage(map);
        logger.info("====companyByPage:"   + positionByPage);
        return positionByPage;

    }

    @RequestMapping("/getPositionById")
    public @ResponseBody
    Position getPositionById(@RequestParam(value = "positionId")Integer positionId){
        logger.info("=====通过职位ID查询职位信息======");
        logger.info("====PositionId:"    + positionId);

        //调用业务层
        Position positionByPage = positionService.getPositionInfoById(positionId);
        logger.info("====companyByPage:"   + positionByPage);
        return positionByPage;
    }

 /*   @RequestMapping("/deletePositionInfo")
    public @ResponseBody
    int deletePositionInfo(@RequestParam(value = "positionId")String positionId){
        logger.info("=====通过职位ID删除职位信息======");
        logger.info("====Id:"    + positionId);

        //调用业务层
        int Id = Integer.parseInt(positionId);
        int companyByPage = PositionService.deletePositionInfo(Id);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }*/



    @RequestMapping("/updatePositionInfo")
    public @ResponseBody
    int updatePositionInfo(@RequestParam(value = "positionName")String positionName,
                           @RequestParam(value = "describtion")String describtion,
                           @RequestParam(value = "positionId")Integer positionId){
        logger.info("=====通过职位ID修改职位信息======");
        logger.info("====positionName:"  + positionName);
        logger.info("====describtion:"    + describtion);
        logger.info("====positionId:"  + positionId);


        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("positionName",positionName);
        map.put("describtion",describtion);
        map.put("positionId",positionId);
        int companyByPage = positionService.updatePositionInfo(map);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }

    @RequestMapping("/addPositionInfo")
    public @ResponseBody
    int addPositionInfo(@RequestParam(value = "positionName")String positionName,
                        @RequestParam(value = "describtion")String describtion,
                        @RequestParam(value = "positionId")Integer positionId){
        logger.info("======添加职位信息======");
        logger.info("====positionName:"  + positionName);
        logger.info("====describtion:"    + describtion);
        logger.info("====positionId:"  + positionId);

        //调用业务层
        Map<String, Object> map = new HashMap<>();
        map.put("positionName",positionName);
        map.put("describtion",describtion);
        map.put("positionId",positionId);

        int companyByPage = positionService.addPositionInfo(map);
        logger.info("====companyByPage:"   + companyByPage);
        return companyByPage;
    }





}
